

const div = document.querySelector('div')


let offsetX = null
let offsetY = null

function move(v){
    const X = v.clientX - offsetX
    const Y = v.clientY - offsetY

    div.style.top = Y + 'px'
    div.style.left = X + 'px'
}

div.addEventListener('mousedown',e => {
    offsetX = e.offsetX
    offsetY = e.offsetY

    document.addEventListener('mousemove',move)

})

div.addEventListener('mouseup',i => {
    document.removeEventListener('mousemove',move)
})